package cn.demarcia.coco.ui.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.demarcia.coco.R;
import cn.demarcia.coco.uihelper.UIHelper;
import info.jimao.newsdk.models.WeatherDataModel;

/**
 * Created by lzy
 * on 2016/8/8.
 */
public class WeekWeatherAdapter extends RecyclerView.Adapter<WeekWeatherAdapter.ViewHolder> {
    private Context context;
    private final LayoutInflater layoutInflater;
    private List<Object> items = new ArrayList<>();

    public WeekWeatherAdapter(Context context, List<Object> items) {
        this.context = context;
        this.items = items;
        this.layoutInflater = LayoutInflater.from(context);
    }


    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(layoutInflater.inflate(R.layout.list_item_weather_week, parent, false));
    }

    @Override
    public void onBindViewHolder(WeekWeatherAdapter.ViewHolder holder, int position) {
        final WeatherDataModel.WeatherBean item = (WeatherDataModel.WeatherBean) items.get(position);
        if (position == 0) {
            holder.tvWeekday.setText("今天");
        } else if (position == 1) {
            holder.tvWeekday.setText("明天");
        } else {
            holder.tvWeekday.setText(context.getString(R.string.week_day, item.getWeek()));
        }

        UIHelper.showWeatherIcon(holder.ivWeather, item.getInfo().getDay().get(1));

        holder.tvTemperature.setText(context.getString(R.string.temperature_day_to_night, item.getInfo().getDay().get(2), item.getInfo().getNight().get(2)));
    }

    @Override
    public int getItemCount() {
        return items == null ? 0 : (items.size() > 6 ? 6 : items.size());//只显示未来5天的天气
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.tvDate)
        TextView tvWeekday;
        @Bind(R.id.tvTemperature)
        TextView tvTemperature;
        @Bind(R.id.ivWeather)
        ImageView ivWeather;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
